package selenium.WebDriverTest;

import org.openqa.selenium.*;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Wait;



public class chrome {

	public static boolean isPresentEle(By by, WebDriver driver) {
		try {
			driver.findElement(by);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	public static void main(String[] args) throws InterruptedException {
		// TODO Auto-generated method stub

		System.setProperty("webdriver.chrome.driver", "D:\\soft\\test\\selenium3\\driver\\chromedriver.exe");
		WebDriver wd=new ChromeDriver();
		//wd.get("http://www.qq.com");
		wd.get("http://www.baidu.com");
		wd.manage().window().maximize();
		
		if(isPresentEle(By.id("kw"), wd)) {
			System.out.println("找到元素");
			WebElement text= wd.findElement(By.id("kw"));
			

			WebElement ty = wd.findElement(By.id("kw"));
			String color=ty.getCssValue("color");
			System.out.println("type:"+ty.getAttribute("name"));
			System.out.println("color:"+color);	
			text.sendKeys("css");
			text.submit();
			
			
		
		//wd.navigate().to("http://www.baidu.com");
//		wd.quit();
		
		


 

		
		
		//wd.manage().window().setSize(new Dimension(900, 500));
		
		
		//JavascriptExecutor js=(JavascriptExecutor) wd;
		
		//js.executeScript("window.scrollTo(0,document.body.scrollHeight);");
		
		//js.executeScript("window.scroll(0,document.body.scrollHeight)");
		//将页面滚动条拖到底部
	    //((JavascriptExecutor)wd).executeScript("window.scrollTo(0,document.body.scrollHeight);");
		
		
		
		wd.findElement(By.linkText("新闻")).click();
		wd.navigate().back();
		wd.navigate().forward();
		System.out.printf("back to %s \n", wd.getCurrentUrl());
	    
		System.out.println("forward");
		wd.navigate().forward();
		System.out.printf("back to %s \n", wd.getCurrentUrl());
	    //Thread.sleep(5000);
	    
		System.out.println("refresh");
		//wd.navigate().refresh();
		
		for(int i=0;i<2;i++){
			System.out.println("i="+i);
			
			Thread.sleep(5000);
			
			wd.navigate().forward();
			
			//System.out.println("5秒后，quit");
			//Thread.sleep(20000);
			//wd.quit();
		}
	    
		System.out.println("5秒后，quit");
		wd.quit();
	   
	}
	
		else {
			System.out.println("对象不能找到");
			Thread.sleep(5000);
			wd.close();
			wd.quit();
		}

	}	

		
}
